package com.hgkj.cloud.base.scheme;

import com.alibaba.fastjson.JSONObject;
import com.hgkj.cloud.base.file.FileProcess;
import com.hgkj.cloud.base.file.FileSaver;
import com.hgkj.cloud.base.file.FileSourceGenerator;
import com.hgkj.cloud.base.service.impl.RemoteServiceImpl;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.codec.binary.Base64;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.math.BigDecimal;
import java.util.Map;
import java.util.Properties;

/**
 * 量表报告图片生成部分
 */
public class ClsGraph {
	@Setter
	@Getter
	public static final class ImageContent {
		private String Title; // 标题
		private int Width;
		private int Height;
		private int Left;
		private int Right;
		private int Top;
		private int Bottom;
		private int MinValue;
		private int MaxValue;
		private int Multiple;
		private int BottomHeight;
	}

	@Setter
	@Getter
	public static final class GeneContent {
		private float[] Value;
		private String[] Title;
	}

	JSONObject jsonObject;
	Map<String, Object> map;

	/**
	 * 图片生成
	 * 
	 * @param vEnglish 量表英文编码
	 * @param vChinese 量表中文名称
	 * @param map      量表数据
	 */
	public static String InsertImage(String vEnglish, String vChinese, Map map) {
		try {
			String strReturn = "";
			String strPicURL = "";

			int i = 0;

			ImageContent ic = new ImageContent();

			GeneContent gene;

			switch (vEnglish) {
			case "Pf16": // 四、卡特尔16种个性测验（16Pf）
				if (true) {
					ic.setTitle(vChinese);
					ic.setLeft(50);
					ic.setRight(40);
					ic.setTop(50);
					ic.setBottom(70);
					ic.setWidth(540);
					ic.setHeight(320);

					String geneTitle = "乐群,聪慧,稳定,恃强,兴奋,有恒,敢为,敏感,怀疑,幻想,世故,忧虑,实验,独立,自律,紧张";
					String[] aGeneTitle = geneTitle.split(",");

					String[] geName1 = "Lqx,Chx,Wdx,Cqx,Xfx,Yhx,Gwx,Mgx,Hyx,Hxx,Sgx,Ylx,Syx,Dlx,Zlx,Jzx".toLowerCase()
							.split(",");
					float[] aGeneValue = new float[geName1.length];

					for (i = 0; i < geName1.length; i++) {
						aGeneValue[i] = Float.valueOf(String.valueOf(map.get(geName1[i] + "_s")));
					}

					gene = new GeneContent();
					gene.setTitle(aGeneTitle);
					gene.setValue(aGeneValue);

					strPicURL = Draw16PfGraph(ic, gene);
				}
				break;
			case "Mmpi399":// 五、六、明尼苏达多相人格测验(399题)（Mmpi399）,明尼苏达多相人格测验(566题)（Mmpi566）
			case "Mmpi566":
				if (true) {
					ic.setTitle(vChinese);
					ic.setLeft(50);
					ic.setRight(40);
					ic.setTop(50);
					ic.setBottom(70);
					ic.setWidth(540);
					ic.setHeight(450);

					String geneTitle = "";
					String[] geName1 = null;
					switch (vEnglish) {
					case "Mmpi399":
						geneTitle = "?,L,F,K,Hs,D,Hy,Pd,Mf,Pa,Pt,Sc,Ma,Si";
						geName1 = "Drop_o,Lie_s,Infra_s,Defen_s,Hypoch_s,Depre_s,Hyste_s,Psychop_s,Mascu_s,Para_s,Psychas_s,Schi_s,Hypoma_s,Social_s"
								.toLowerCase().split(",");
						break;
					case "Mmpi566":
						geneTitle = "?,L,F,K,Hs,D,Hy,Pd,Mf,Pa,Pt,Sc,Ma,Si,Mas,Dy,Do,Re,Cn";
						geName1 = "Drop_o,Lie_s,Infra_s,Defen_s,Hypoch_s,Depre_s,Hyste_s,Psychop_s,Mascu_s,Para_s,Psychas_s,Schi_s,Hypoma_s,Social_s,Mani_s,Depend_s,Domi_s,Respon_s,Control_s"
								.toLowerCase().split(",");
						break;
					}

					// String geneTitle = "?,L,F,K,Hs,D,Hy,Pd,Mf,Pa,Pt,Sc,Ma,Si,Mas,Dy,Do,Re,Cn";
					// String geneTitle = "?,L,F,K,Hs,D,Hy,Pd,Mf,Pa,Pt,Sc,Ma,Si";
					String[] aGeneTitle = geneTitle.split(",");

					// String[] geName1 =
					// "Drop_o,Lie_s,Infra_s,Defen_s,Hypoch_s,Depre_s,Hyste_s,Psychop_s,Mascu_s,Para_s,Psychas_s,Schi_s,Hypoma_s,Social_s,Mani_s,Depend_s,Domi_s,Respon_s,Control_s".toLowerCase().split(",");
					// String[] geName1 =
					// "Drop_o,Lie_s,Infra_s,Defen_s,Hypoch_s,Depre_s,Hyste_s,Psychop_s,Mascu_s,Para_s,Psychas_s,Schi_s,Hypoma_s,Social_s".toLowerCase().split(",");

					float[] aGeneValue = new float[geName1.length];

					for (i = 0; i < geName1.length; i++) {
						aGeneValue[i] = Float.valueOf(String.valueOf(map.get(geName1[i])));
					}

					gene = new GeneContent();
					gene.setTitle(aGeneTitle);
					gene.setValue(aGeneValue);

					strPicURL = DrawMmpiGraph(ic, gene);
				}
				break;
			case "Epq": // 七、艾森克个性测验(成人)Epq
			case "Xepq": // 八、艾森克个性测验(儿童)Xepq
				if (true) {
					ic.setTitle(vChinese);
					ic.setLeft(50);
					ic.setRight(40);
					ic.setTop(50);
					ic.setBottom(50);
					ic.setWidth(320);
					ic.setHeight(600);

					String geneTitle = "内外向,神经,精神,掩饰";
					String[] aGeneTitle = geneTitle.split(",");

					String[] geName1 = "Nwx_s,Sjz_s,Jsz_s,Yscd_s".toLowerCase().split(",");

					float[] aGeneValue = new float[geName1.length];

					for (i = 0; i < geName1.length; i++) {
						aGeneValue[i] = Float.valueOf(String.valueOf(map.get(geName1[i])));
					}

					gene = new GeneContent();
					gene.setTitle(aGeneTitle);
					gene.setValue(aGeneValue);

					strPicURL = DrawXepqGraph(ic, gene);
				}
				break;
			case "Epps": // 九、爱德华个性偏好测验Epps
				if (true) {
					ic.setTitle(vChinese);
					ic.setLeft(50);
					ic.setRight(50);
					ic.setTop(50);
					ic.setBottom(70);
					ic.setWidth(540);
					ic.setHeight(320);

					String geneTitle = "成就,崇拜,次序,表现,自主,亲近,探究,求助,支配,谦卑,慈善,变异,坚毅,性爱,攻击";
					String[] aGeneTitle = geneTitle.split(",");

					String[] geName1 = "Cjy_s,Cby_s,Cxx_s,Bxy_s,Zzx_s,Qjx_s,Tjy_s,Qzx_s,Zpx_s,Qbx_s,Csx_s,Byx_s,Jyx_s,Xa_s,Gjx_s"
							.toLowerCase().split(",");

					float[] aGeneValue = new float[geName1.length];

					for (i = 0; i < geName1.length; i++) {
						aGeneValue[i] = Float.valueOf(String.valueOf(map.get(geName1[i])));
					}

					gene = new GeneContent();
					gene.setTitle(aGeneTitle);
					gene.setValue(aGeneValue);

					strPicURL = DrawEppsGraph(ic, gene);
				}
				break;
			case "Scl90": // 十二、90项症状清单Scl90(Scl90)
				if (true) {
					ic.setTitle(vChinese);
					ic.setLeft(41);
					ic.setRight(32);
					ic.setTop(50);
					ic.setBottom(70);
					ic.setWidth(540);
					ic.setHeight(320);

					String geneTitle = "躯体化,强迫症状,人际关系敏感,抑郁,焦虑,敌对,恐怖,偏执,精神病性,其他项目";
					String[] aGeneTitle = geneTitle.split(",");

					String[] geName1 = "Som_ave,Obs_ave,Int_ave,Dep_ave,Anx_ave,Hos_ave,Pno_ave,Par_ave,Psy_ave,Other_ave"
							.toLowerCase().split(",");

					float[] aGeneValue = new float[geName1.length];

					for (i = 0; i < geName1.length; i++) {
						aGeneValue[i] = Float.valueOf(String.valueOf(map.get(geName1[i])));
					}

					gene = new GeneContent();
					gene.setTitle(aGeneTitle);
					gene.setValue(aGeneValue);

					strPicURL = DrawScl90Graph(ic, gene);
				}
				break;
			default:
				strPicURL = "";
				break;
			}

			if (strPicURL.equals("")) {
				strReturn = "";
			} else {
				strReturn += "<table cellpadding='0'cellspacing='0' width='540' border='0'>";
				strReturn += "<tr><td align='center'><img src='data:image/jpg;base64," + strPicURL + "'/>"
						+ "</td></tr></table>";
			}

			return strReturn;
		} catch (Exception e) {
			return "";
		}
	}

	// 画图(4, 16Pf)
	private static String Draw16PfGraph(ImageContent vIC, GeneContent vGene) {
		try {
			BufferedImage bmDraw = new BufferedImage(vIC.getWidth(), vIC.getHeight(), BufferedImage.TYPE_INT_RGB);
			Graphics gpDraw = bmDraw.getGraphics();
			// 使用java.awt.Graphics2D的setStroke方法就可以解决这个小问题
			// 一个Graphics对象可以强制转化为Graphics2D类型(向下转型)
			// 主要解决画线的粗细问题
			Graphics2D g2 = (Graphics2D) gpDraw; // g是Graphics对象

			// 背景色
			gpDraw.setColor(Color.WHITE);
			gpDraw.fillRect(1, 1, vIC.getWidth() - 1, vIC.getHeight() - 1);
			gpDraw.setColor(Color.BLACK);
			gpDraw.drawRect(0, 0, vIC.getWidth() - 1, vIC.getHeight() - 1);

			int i;
			Font fontTitle = new Font("宋体", Font.BOLD, 16);
			Font font = new Font("宋体", Font.PLAIN, 10);

			// 画X，Y轴
			gpDraw.setFont(fontTitle);
			gpDraw.drawString(vIC.getTitle(), (vIC.getWidth() - vIC.getLeft() - vIC.getRight()) / 2 - 40,
					vIC.getTop() / 2 + 15);
			gpDraw.drawLine(vIC.getLeft(), vIC.getTop(), vIC.getLeft(), vIC.getHeight() - vIC.getBottom()); // Y轴
			gpDraw.drawLine(vIC.getLeft(), vIC.getHeight() - vIC.getBottom(), vIC.getWidth() - vIC.getRight(),
					vIC.getHeight() - vIC.getBottom()); // X轴

			// Y轴分隔
			int YDis = Math.round(Float.valueOf((vIC.getHeight() - vIC.getTop() - vIC.getBottom()) / 70f));
			int intLength = 0;

			for (i = 0; i < 68; i++) {
				intLength = 3;
				if (i % 5 == 0) {
					intLength = vIC.getWidth() - vIC.getLeft() - vIC.getRight();
					BigDecimal bd = new BigDecimal(0.2 * (i - 5));
					String strTemp = String.valueOf(bd.setScale(2, BigDecimal.ROUND_HALF_UP).toString());// floatValue());
					gpDraw.setFont(font);
					gpDraw.setColor(Color.BLACK);
					gpDraw.drawString(strTemp, vIC.getLeft() - 30, vIC.getHeight() - vIC.getBottom() - (YDis * i) + 5);
				}
				if (i > 0) {
					if (i == 30) {
						gpDraw.setColor(Color.BLUE);
						gpDraw.drawLine(vIC.getLeft(), vIC.getHeight() - vIC.getBottom() - (YDis * i),
								vIC.getLeft() + intLength, vIC.getHeight() - vIC.getBottom() - (YDis * i));
					} else {
						gpDraw.setColor(Color.GRAY);
						gpDraw.drawLine(vIC.getLeft(), vIC.getHeight() - vIC.getBottom() - (YDis * i),
								vIC.getLeft() + intLength, vIC.getHeight() - vIC.getBottom() - (YDis * i));
					}
				}
			}

			// X轴分隔
			int XDis = Math.round(Float.valueOf(vIC.getWidth() - vIC.getLeft() - vIC.getRight())
					/ Float.valueOf(vGene.Title.length - 1));
			for (i = 0; i < vGene.Title.length; i++) {
				if (i > 0) {
					gpDraw.setColor(Color.GRAY);
					g2.setStroke(new BasicStroke(1.0f));
					gpDraw.drawLine(vIC.getLeft() + (XDis * i), vIC.getHeight() - vIC.getBottom(),
							vIC.getLeft() + (XDis * i), vIC.getTop());
				}
				// 因子名称
				gpDraw.setColor(Color.BLACK);
				gpDraw.setFont(font);
				gpDraw.drawString(vGene.Title[i], vIC.getLeft() + (XDis * i) - 5,
						vIC.getHeight() - vIC.getBottom() + 20);

				// 因子得分
				gpDraw.setColor(Color.BLACK);
				gpDraw.setFont(font);
				BigDecimal bd = new BigDecimal(vGene.Value[i]);
				String strTemp = String.valueOf(bd.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue());
				gpDraw.drawString(strTemp, vIC.getLeft() + (XDis * i) - 10, vIC.getHeight() - vIC.getBottom() + 40);

				// 因子得分点
				if (i > 0) {
					gpDraw.setColor(Color.RED);
					g2.setStroke(new BasicStroke(4.0f));
					gpDraw.drawLine(vIC.getLeft() + (XDis * (i - 1)),
							vIC.getHeight() - vIC.getBottom()
									- Math.round(Float.valueOf((vGene.Value[i - 1] + 1) * 5 * YDis)),
							vIC.getLeft() + (XDis * i), vIC.getHeight() - vIC.getBottom()
									- Math.round(Float.valueOf((vGene.Value[i] + 1) * 5 * YDis)));
				}
			}

			String base64Img = "";
			base64Img = ImgToBase64String(bmDraw);
			gpDraw.dispose();

			return base64Img;
		} catch (Exception e) {
			return "";
		}
	}

	// 画图(5,6, Mmpi)
	private static String DrawMmpiGraph(ImageContent vIC, GeneContent vGene) {
		try {
			BufferedImage bmDraw = new BufferedImage(vIC.getWidth(), vIC.getHeight(), BufferedImage.TYPE_INT_RGB);
			Graphics gpDraw = bmDraw.getGraphics();
			// 使用java.awt.Graphics2D的setStroke方法就可以解决这个小问题
			// 一个Graphics对象可以强制转化为Graphics2D类型(向下转型)
			// 主要解决画线的粗细问题
			Graphics2D g2 = (Graphics2D) gpDraw; // g是Graphics对象

			// 背景色
			gpDraw.setColor(Color.WHITE);
			gpDraw.fillRect(1, 1, vIC.getWidth() - 1, vIC.getHeight() - 1);
			gpDraw.setColor(Color.BLACK);
			gpDraw.drawRect(0, 0, vIC.getWidth() - 1, vIC.getHeight() - 1);

			int i;
			Font fontTitle = new Font("宋体", Font.BOLD, 16);
			Font font = new Font("宋体", Font.PLAIN, 10);

			// 画X，Y轴
			gpDraw.setFont(fontTitle);
			gpDraw.drawString(vIC.getTitle(), (vIC.getWidth() - vIC.getLeft() - vIC.getRight()) / 2 - 40,
					vIC.getTop() / 2 + 15);
			gpDraw.drawLine(vIC.getLeft(), vIC.getTop(), vIC.getLeft(), vIC.getHeight() - vIC.getBottom()); // Y轴
			gpDraw.drawLine(vIC.getLeft(), vIC.getHeight() - vIC.getBottom(), vIC.getWidth() - vIC.getRight(),
					vIC.getHeight() - vIC.getBottom()); // X轴

			// Y轴分隔
			int YDis = Math.round(Float.valueOf((vIC.getHeight() - vIC.getTop() - vIC.getBottom()) / 120f));
			int intLength = 0;

			for (i = 0; i < 106; i++) {
				intLength = 3;
				if (i % 5 == 0) {
					intLength = vIC.getWidth() - vIC.getLeft() - vIC.getRight();
					String strTemp = String.valueOf(i);
					gpDraw.setFont(font);
					gpDraw.setColor(Color.BLACK);
					gpDraw.drawString(strTemp, vIC.getLeft() - 30, vIC.getHeight() - vIC.getBottom() - (YDis * i) + 5);
				}
				if (i > 0) {
					switch (i) {
					case 50:
					case 55:
					case 60:
						gpDraw.setColor(Color.BLUE);
						break;
					default:
						gpDraw.setColor(Color.GRAY);
						break;
					}
					gpDraw.drawLine(vIC.getLeft(), vIC.getHeight() - vIC.getBottom() - (YDis * i),
							vIC.getLeft() + intLength, vIC.getHeight() - vIC.getBottom() - (YDis * i));

				}
			}

			// X轴分隔
			int XDis = Math.round(Float.valueOf(vIC.getWidth() - vIC.getLeft() - vIC.getRight())
					/ Float.valueOf(vGene.Title.length - 1));
			for (i = 0; i < vGene.Title.length; i++) {
				if (i > 0) {
					gpDraw.setColor(Color.GRAY);
					g2.setStroke(new BasicStroke(1.0f));
					gpDraw.drawLine(vIC.getLeft() + (XDis * i), vIC.getHeight() - vIC.getBottom(),
							vIC.getLeft() + (XDis * i), vIC.getTop());
				}
				// 因子名称
				gpDraw.setColor(Color.BLACK);
				gpDraw.setFont(font);
				gpDraw.drawString(vGene.Title[i], vIC.getLeft() + (XDis * i) - 5,
						vIC.getHeight() - vIC.getBottom() + 20);

				// 因子得分
				gpDraw.setColor(Color.BLACK);
				gpDraw.setFont(font);
				String strTemp = String.valueOf(Math.round(vGene.Value[i]));
				gpDraw.drawString(strTemp, vIC.getLeft() + (XDis * i) - 7, vIC.getHeight() - vIC.getBottom() + 40);

				// 因子得分点
				if (i > 1) {
					gpDraw.setColor(Color.RED);
					g2.setStroke(new BasicStroke(4.0f));
					gpDraw.drawLine(vIC.getLeft() + (XDis * (i - 1)),
							vIC.getHeight() - vIC.getBottom()
									- Math.round(Float.valueOf((vGene.Value[i - 1] + 1) * YDis)),
							vIC.getLeft() + (XDis * i),
							vIC.getHeight() - vIC.getBottom() - Math.round(Float.valueOf((vGene.Value[i] + 1) * YDis)));
				}
			}

			String base64Img = "";
			base64Img = ImgToBase64String(bmDraw);
			gpDraw.dispose();

			return base64Img;
		} catch (Exception e) {
			return "";
		}
	}

	// 画图(7,8,Epq, Xepq)
	private static String DrawXepqGraph(ImageContent vIC, GeneContent vGene) {
		try {
			BufferedImage bmDraw = new BufferedImage(vIC.getWidth(), vIC.getHeight(), BufferedImage.TYPE_INT_RGB);
			Graphics gpDraw = bmDraw.getGraphics();
			// 使用java.awt.Graphics2D的setStroke方法就可以解决这个小问题
			// 一个Graphics对象可以强制转化为Graphics2D类型(向下转型)
			// 主要解决画线的粗细问题
			Graphics2D g2 = (Graphics2D) gpDraw; // g是Graphics对象

			// 背景色
			gpDraw.setColor(Color.WHITE);
			gpDraw.fillRect(1, 1, vIC.getWidth() - 1, vIC.getHeight() - 1);
			gpDraw.setColor(Color.BLACK);
			gpDraw.drawRect(0, 0, vIC.getWidth() - 1, vIC.getHeight() - 1);

			int i;
			int j;
			Font fontTitle = new Font("宋体", Font.BOLD, 16);
			Font font = new Font("宋体", Font.PLAIN, 10);

			// 画标题
			gpDraw.setFont(fontTitle);
			gpDraw.drawString(vIC.getTitle(), (vIC.getWidth() - vIC.getLeft() - vIC.getRight()) / 2 - 40,
					vIC.getTop() / 2 + 15);

			float lengthXY = vIC.getWidth() - vIC.getLeft() - vIC.getRight();
			float beginX = vIC.getLeft();
			float beginY = Math.round(Float.valueOf((vIC.getHeight() - vIC.getTop() * 3 - vIC.getBottom() * 2) / 2));

			float[] dis = { 38.6f, 43.3f, 50f, 56.7f, 61.5f };
			for (i = 0; i < dis.length; i++) {
				dis[i] /= 5;
			}

			float spX = Math.round(Float.valueOf(lengthXY / 20f)); // 每一格是5

			gpDraw.setFont(font);
			gpDraw.setColor(Color.BLACK);
			gpDraw.drawString("E", Math.round(beginX - 15), Math.round(beginY + 10));
			gpDraw.drawString("N", Math.round(Float.valueOf((beginX + lengthXY / 2) + 0)),
					Math.round(Float.valueOf((beginY + lengthXY / 2) + 25)));

			for (i = 0; i < dis.length; i++) {
				if (i != 0 && i != 4) {
					gpDraw.drawLine(Math.round(beginX), Math.round((beginY - lengthXY / 2) + dis[i] * spX),
							Math.round(beginX + lengthXY + 10), Math.round((beginY - lengthXY / 2) + dis[i] * spX)); // 横
					gpDraw.drawLine(Math.round(beginX + dis[i] * spX), Math.round(beginY - lengthXY / 2),
							Math.round(beginX + dis[i] * spX), Math.round(beginY + lengthXY / 2) + 10); // 竖
				}
			}

			// 分隔轴
			/*
			 * Font font1 = new Font("宋体", Font.PLAIN, 8); gpDraw.setFont(font1);
			 */
			for (i = 0; i < 21; i++) {
				gpDraw.drawLine(Math.round(beginX + spX * i), Math.round(beginY - 3) + 5, Math.round(beginX + spX * i),
						Math.round(beginY + 3) + 5); // 横
				if (i % 2 == 0) {
					gpDraw.drawString(String.valueOf(i * 5), Math.round(beginX + spX * i - 5), Math.round(beginY + 18));
				}

				gpDraw.drawLine(Math.round((beginX + lengthXY / 2) - 3) + 5,
						Math.round((beginY - lengthXY / 2) + spX * i), Math.round((beginX + lengthXY / 2) + 3) + 5,
						Math.round((beginY - lengthXY / 2) + spX * i)); // 竖
				if (i % 2 == 0 && i != 10) {
					gpDraw.drawString(String.valueOf(i * 5), Math.round((beginX + lengthXY / 2) + 10),
							Math.round((beginY + lengthXY / 2) - spX * i + 15));
				}
			}

			// 小标题
			String[] aName = "内向，不稳定,外向，不稳定,内向，稳定,外向，稳定".split(",");
			gpDraw.drawString(aName[0], Math.round(beginX), Math.round(beginY - lengthXY / 4 - spX) + 10);
			gpDraw.drawString(aName[1], Math.round(beginX + lengthXY / 2 + spX * 4),
					Math.round(beginY - lengthXY / 4 - spX) + 10);
			gpDraw.drawString(aName[2], Math.round(beginX), Math.round(beginY + lengthXY / 4 + spX) + 10);
			gpDraw.drawString(aName[3], Math.round(beginX + lengthXY / 2 + spX * 4),
					Math.round(beginY + lengthXY / 4 + spX) + 10);

			// E分和N分
			gpDraw.drawString("E:" + String.valueOf((int) vGene.Value[0]), Math.round(beginX + lengthXY / 2 + spX * 7),
					Math.round(beginY - lengthXY / 2 + spX) + 10);
			gpDraw.drawString("N:" + String.valueOf((int) vGene.Value[1]), Math.round(beginX + lengthXY / 2 + spX * 7),
					Math.round(beginY - lengthXY / 2 + spX * 2) + 10);

			Float pointX = beginX + vGene.Value[0] * spX / 5 - 3;
			Float pointY = beginY + (lengthXY / 2) - vGene.Value[1] * spX / 5 - 3 + 10;
			gpDraw.setColor(Color.RED);
			// 2号粗线
			g2.setStroke(new BasicStroke(2.0f));
			gpDraw.drawOval(Math.round(pointX), Math.round(pointY), 6, 6);

			// 回到最细的线
			g2.setStroke(new BasicStroke(1.0f));

			// 第二个图
			beginX = vIC.getLeft() + vIC.getRight();
			beginY = vIC.getHeight() - vIC.getBottom();
			float lengthX = (vIC.getWidth() - vIC.getLeft() - vIC.getRight()) / 3 * 2;
			float lengthY = vIC.getWidth() - vIC.getLeft() - vIC.getRight();

			gpDraw.setColor(Color.BLACK);

			// X轴
			gpDraw.drawLine(Math.round(beginX), Math.round(beginY) + 10, Math.round(beginX + lengthX),
					Math.round(beginY) + 10);
			gpDraw.drawLine(Math.round(beginX), Math.round(beginY - lengthY) + 10, Math.round(beginX + lengthX),
					Math.round(beginY - lengthY) + 10);

			// Y轴
			float bigY = lengthX / 5;
			for (i = 0; i < 6; i++) {
				gpDraw.drawLine(Math.round(beginX + bigY * i), Math.round(beginY) + 10, Math.round(beginX + bigY * i),
						Math.round(beginY - lengthY) + 10);
			}

			for (i = 1; i < 5; i++) {
				// 因子标识
				if (i == 1) {
					gpDraw.drawString(vGene.Title[i - 1], Math.round(beginX + bigY * i - 2) - 10,
							Math.round(beginY + 5) + 20);
				} else {
					gpDraw.drawString(vGene.Title[i - 1], Math.round(beginX + bigY * i - 2) - 5,
							Math.round(beginY + 5) + 20);
				}
				// 因子分值
				gpDraw.drawString(String.valueOf((int) vGene.Value[i - 1]), Math.round(beginX + bigY * i - 4),
						Math.round(beginY + spX + 5) + 20);
			}

			// Y轴分隔
			float spY = lengthY / 20;
			for (i = 0; i < 6; i++) {
				for (j = 0; j < 21; j++) {
					gpDraw.drawLine(Math.round(beginX + bigY * i), Math.round(beginY - spY * j) + 10,
							Math.round(beginX + bigY * i + 3), Math.round(beginY - spY * j) + 10);
				}
			}

			// 数字标识
			for (i = 0; i < 21; i++) {
				if (i % 2 == 0) {
					gpDraw.drawString(String.valueOf(i * 5), Math.round(beginX - 20),
							Math.round(beginY - spY * i - 5) + 20);
					gpDraw.drawString(String.valueOf(i * 5), Math.round(beginX + bigY * 5 + 5),
							Math.round(beginY - spY * i - 5) + 20);
				}
			}

			// 特殊线
			for (i = 0; i < dis.length; i++) {
				if (i != 0 && i != 4) {
					gpDraw.drawLine(Math.round(beginX), Math.round(beginY - dis[i] * spY) + 10,
							Math.round(beginX + lengthX), Math.round(beginY - dis[i] * spY) + 10); // 横
				}
			}

			gpDraw.setColor(Color.RED);
			g2.setStroke(new BasicStroke(4.0f));
			for (i = 0; i < vGene.Title.length; i++) {
				// 因子得分点
				if (i > 0) {
					gpDraw.drawLine(Math.round(beginX + bigY * i),
							Math.round(beginY - Float.valueOf((vGene.Value[i - 1]) * spY / 5)) + 10,
							Math.round(beginX + bigY * (i + 1)),
							Math.round(beginY - Float.valueOf((vGene.Value[i]) * spY / 5)) + 10);
				}
			}

			// 以下是画第二张图的虚线
			// 虚线的方式，因为不知道怎么画完虚线以后转回实线，所以这个虚线最后画
			gpDraw.setColor(Color.BLACK);
			for (i = 0; i < dis.length; i++) {
				if (i == 0 || i == 4) {
					// 虚线的方式，因为不知道怎么画完虚线以后转回实线，所以这个虚线最后画
					float[] dash = { 2, 2 }; // 短划线图案
					BasicStroke bs = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash,
							0.0f); // 实例化新画刷
					g2.setStroke(bs); // 设置新的画刷
					gpDraw.drawLine(Math.round(beginX), Math.round(beginY - dis[i] * spY) + 10,
							Math.round(beginX + lengthX), Math.round(beginY - dis[i] * spY) + 10); // 横
				}
			}

			// 以下是画第一张图的虚线
			// 虚线的方式，因为不知道怎么画完虚线以后转回实线，所以这个虚线最后画
			// 这里重新给第一个图的参数赋值，用于画虚线
			lengthXY = vIC.getWidth() - vIC.getLeft() - vIC.getRight();
			beginX = vIC.getLeft();
			beginY = Math.round(Float.valueOf((vIC.getHeight() - vIC.getTop() * 3 - vIC.getBottom() * 2) / 2));

			// 虚线的方式，因为不知道怎么画完虚线以后转回实线，所以这个虚线最后画
			gpDraw.setColor(Color.BLACK);
			for (i = 0; i < dis.length; i++) {
				if (i == 0 || i == 4) {
					// 虚线的方式，因为不知道怎么画完虚线以后转回实线，所以这个虚线最后画
					float[] dash = { 2, 2 }; // 短划线图案
					BasicStroke bs = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash,
							0.0f); // 实例化新画刷
					g2.setStroke(bs); // 设置新的画刷
					gpDraw.drawLine(Math.round(beginX), Math.round((beginY - lengthXY / 2) + dis[i] * spX),
							Math.round(beginX + lengthXY + 12), Math.round((beginY - lengthXY / 2) + dis[i] * spX)); // 横
					gpDraw.drawLine(Math.round(beginX + dis[i] * spX), Math.round(beginY - lengthXY / 2),
							Math.round(beginX + dis[i] * spX), Math.round(beginY + lengthXY / 2) + 12); // 竖
				}
			}

			String base64Img = "";
			base64Img = ImgToBase64String(bmDraw);
			gpDraw.dispose();

			return base64Img;
		} catch (Exception e) {
			return "";
		}
	}

	// 画图(9, Epps)
	private static String DrawEppsGraph(ImageContent vIC, GeneContent vGene) {
		try {
			BufferedImage bmDraw = new BufferedImage(vIC.getWidth(), vIC.getHeight(), BufferedImage.TYPE_INT_RGB);
			Graphics gpDraw = bmDraw.getGraphics();
			// 使用java.awt.Graphics2D的setStroke方法就可以解决这个小问题
			// 一个Graphics对象可以强制转化为Graphics2D类型(向下转型)
			// 主要解决画线的粗细问题
			Graphics2D g2 = (Graphics2D) gpDraw; // g是Graphics对象

			// 背景色
			gpDraw.setColor(Color.WHITE);
			gpDraw.fillRect(1, 1, vIC.getWidth() - 1, vIC.getHeight() - 1);
			gpDraw.setColor(Color.BLACK);
			gpDraw.drawRect(0, 0, vIC.getWidth() - 1, vIC.getHeight() - 1);

			int i;
			Font fontTitle = new Font("宋体", Font.BOLD, 16);
			Font font = new Font("宋体", Font.PLAIN, 10);

			// 画X，Y轴
			gpDraw.setFont(fontTitle);
			gpDraw.drawString(vIC.Title, Math.round((vIC.getWidth() - vIC.getLeft() - vIC.getRight()) / 2 - 40),
					Math.round(vIC.getTop() / 2)); // 标题
			gpDraw.drawLine(Math.round(vIC.getLeft()), Math.round(vIC.getTop()), Math.round(vIC.getLeft()),
					Math.round(vIC.getHeight() - vIC.getBottom())); // Y轴
			gpDraw.drawLine(Math.round(vIC.getLeft()), Math.round(vIC.getHeight() - vIC.getBottom()),
					Math.round(vIC.getWidth() - vIC.getRight()) - 5, Math.round(vIC.getHeight() - vIC.getBottom())); // X轴

			// Y轴分隔
			int YDis = Math.round((vIC.getHeight() - vIC.getTop() - vIC.getBottom()) / 100f);
			int intLength = 0;
			gpDraw.setFont(font);
			for (i = 0; i < 91; i++) {
				intLength = 3;
				if (i % 10 == 0) {
					gpDraw.setColor(Color.BLACK);
					intLength = Math.round(vIC.getWidth() - vIC.getLeft() - vIC.getRight() - 5);
					gpDraw.drawString(String.valueOf(i), Math.round(vIC.getLeft() - 20),
							Math.round(vIC.getHeight() - vIC.getBottom() - (YDis * i) - 5) + 10);
				}

				if (i > 0 && i % 5 == 0) {
					gpDraw.setColor(Color.GRAY);
					gpDraw.drawLine(Math.round(vIC.getLeft()),
							Math.round(vIC.getHeight() - vIC.getBottom() - (YDis * i)),
							Math.round(vIC.getLeft() + intLength),
							Math.round(vIC.getHeight() - vIC.getBottom() - (YDis * i)));
				}
			}

			// X轴分隔
			int XDis = Math
					.round((vIC.getWidth() - vIC.getLeft() - vIC.getRight()) / Float.valueOf(vGene.Title.length - 1));
			for (i = 0; i < vGene.Title.length; i++) {
				if (i > 0) {
					gpDraw.setColor(Color.GRAY);
					g2.setStroke(new BasicStroke(1.0f));
					gpDraw.drawLine(Math.round(vIC.getLeft() + (XDis * i)),
							Math.round(vIC.getHeight() - vIC.getBottom()), Math.round(vIC.getLeft() + (XDis * i)),
							Math.round(vIC.getTop()));
				}
				gpDraw.setColor(Color.BLACK);
				// 因子名称
				gpDraw.drawString(vGene.Title[i], Math.round(vIC.getLeft() + (XDis * i) - 10),
						Math.round(vIC.getHeight() - vIC.getBottom() + 10) + 10);
				// 因子得分
				gpDraw.drawString(String.valueOf((int) vGene.Value[i]), Math.round(vIC.getLeft() + (XDis * i) - 10) + 5,
						Math.round(vIC.getHeight() - vIC.getBottom() + 30) + 10);
				// 因子得分点
				if (i > 0) {
					gpDraw.setColor(Color.RED);
					g2.setStroke(new BasicStroke(4.0f));
					gpDraw.drawLine(Math.round(vIC.getLeft() + (XDis * (i - 1))),
							Math.round(vIC.getHeight() - vIC.getBottom() - (vGene.Value[i - 1] + 1) * YDis),
							Math.round(vIC.getLeft() + (XDis * i)),
							Math.round(vIC.getHeight() - vIC.getBottom() - (vGene.Value[i] + 1) * YDis));
				}
			}

			String base64Img = "";
			base64Img = ImgToBase64String(bmDraw);
			gpDraw.dispose();

			return base64Img;
		} catch (Exception e) {
			return "";
		}
	}

	// 画图(12, SCL90)
	private static String DrawScl90Graph(ImageContent vIC, GeneContent vGene) {
		try {
			BufferedImage bmDraw = new BufferedImage(vIC.getWidth(), vIC.getHeight(), BufferedImage.TYPE_INT_RGB);
			Graphics gpDraw = bmDraw.getGraphics();
			// 使用java.awt.Graphics2D的setStroke方法就可以解决这个小问题
			// 一个Graphics对象可以强制转化为Graphics2D类型(向下转型)
			// 主要解决画线的粗细问题
			Graphics2D g2 = (Graphics2D) gpDraw; // g是Graphics对象

			// 背景色
			gpDraw.setColor(Color.WHITE);
			gpDraw.fillRect(1, 1, vIC.getWidth() - 1, vIC.getHeight() - 1);
			gpDraw.setColor(Color.BLACK);
			gpDraw.drawRect(0, 0, vIC.getWidth() - 1, vIC.getHeight() - 1);

			int i;
			Font fontTitle = new Font("宋体", Font.BOLD, 16);
			Font font = new Font("宋体", Font.PLAIN, 10);

			// 画X，Y轴
			gpDraw.setFont(fontTitle);
			gpDraw.drawString(vIC.Title, Math.round((vIC.getWidth() - vIC.getLeft() - vIC.getRight()) / 2) - 30,
					Math.round(vIC.getTop() / 2)); // 标题
			gpDraw.drawLine(Math.round(vIC.getLeft()), Math.round(vIC.getTop()), Math.round(vIC.getLeft()),
					Math.round(vIC.getHeight() - vIC.getBottom())); // Y轴
			gpDraw.drawLine(Math.round(vIC.getLeft()), Math.round(vIC.getHeight() - vIC.getBottom()),
					Math.round(vIC.getWidth() - vIC.getRight()), Math.round(vIC.getHeight() - vIC.getBottom())); // X轴

			// Y轴分隔
			int YDis = Math.round((vIC.getHeight() - vIC.getTop() - vIC.getBottom()) / 50f);
			int intLength = 0;
			// Dim color As Pen
			for (i = 0; i < 51; i++) {
				intLength = 3;
				if (i % 5 == 0) {
					intLength = Math.round(vIC.getWidth() - vIC.getLeft() - vIC.getRight());
					BigDecimal bd = new BigDecimal(0.1 * i);
					String strTemp = String.valueOf(bd.setScale(2, BigDecimal.ROUND_HALF_UP).toString());//
					gpDraw.setFont(font);
					gpDraw.setColor(Color.BLACK);
					gpDraw.drawString(strTemp, Math.round(vIC.getLeft() - 30),
							Math.round(vIC.getHeight() - vIC.getBottom() - (YDis * i) - 5) + 10);
				}
				if (i > 0) {
					gpDraw.setColor(Color.GRAY);
					gpDraw.drawLine(Math.round(vIC.getLeft()),
							Math.round(vIC.getHeight() - vIC.getBottom() - (YDis * i)),
							Math.round(vIC.getLeft() + intLength),
							Math.round(vIC.getHeight() - vIC.getBottom() - (YDis * i)));
				}
			}

			// X轴分隔
			int XDis = Math
					.round((vIC.getWidth() - vIC.getLeft() - vIC.getRight()) / Float.valueOf(vGene.Title.length - 1));
			// Dim geneColor As New Pen(Brushes.Red, 4)
			for (i = 0; i < vGene.Title.length; i++) {
				if (i > 0) {
					gpDraw.setColor(Color.GRAY);
					g2.setStroke(new BasicStroke(1.0f));
					gpDraw.drawLine(Math.round(vIC.getLeft() + (XDis * i)),
							Math.round(vIC.getHeight() - vIC.getBottom()), Math.round(vIC.getLeft() + (XDis * i)),
							Math.round(vIC.getTop()));
				}
				// 因子名称
				gpDraw.setColor(Color.BLACK);
				switch (vGene.Title[i].length()) {
				case 3:
					gpDraw.drawString(vGene.Title[i], Math.round(vIC.getLeft() + (XDis * i) - 18) + 3,
							Math.round(vIC.getHeight() - vIC.getBottom() + 10) + 10);
					break;
				case 4:
					gpDraw.drawString(vGene.Title[i], Math.round(vIC.getLeft() + (XDis * i) - 22) + 3,
							Math.round(vIC.getHeight() - vIC.getBottom() + 10) + 10);
					break;
				case 6:
					gpDraw.drawString(vGene.Title[i].substring(0, 4), Math.round(vIC.getLeft() + (XDis * i) - 22) + 3,
							Math.round(vIC.getHeight() - vIC.getBottom() + 10) + 10);
					gpDraw.drawString(vGene.Title[i].substring(4, vGene.Title[i].length()),
							Math.round(vIC.getLeft() + (XDis * i) - 12) + 3,
							Math.round(vIC.getHeight() - vIC.getBottom() + 20) + 10);
					break;
				default:
					gpDraw.drawString(vGene.Title[i], Math.round(vIC.getLeft() + (XDis * i) - 12) + 3,
							Math.round(vIC.getHeight() - vIC.getBottom() + 10) + 10);
					break;
				}

				// 因子得分
				BigDecimal bd = new BigDecimal(vGene.Value[i]);
				String strTemp = String.valueOf(bd.setScale(2, BigDecimal.ROUND_HALF_UP).toString());//
				gpDraw.drawString(strTemp, Math.round(vIC.getLeft() + (XDis * i) - 15) + 5,
						Math.round(vIC.getHeight() - vIC.getBottom() + 30) + 15);
				// 因子得分点
				if (i > 0) {
					gpDraw.setColor(Color.RED);
					g2.setStroke(new BasicStroke(4.0f));
					gpDraw.drawLine(Math.round(vIC.getLeft() + (XDis * (i - 1))),
							Math.round(vIC.getHeight() - vIC.getBottom() - vGene.Value[i - 1] * 10 * YDis),
							Math.round(vIC.getLeft() + (XDis * i)),
							Math.round(vIC.getHeight() - vIC.getBottom() - vGene.Value[i] * 10 * YDis));
				}
			}

			String base64Img = "";
			base64Img = ImgToBase64String(bmDraw);
			gpDraw.dispose();

			return base64Img;
		} catch (Exception e) {
			return "";
		}
	}

	/**
	 * 图片转化为base64字符串
	 */
	private static String ImgToBase64String(BufferedImage vbmDraw) {
		try {
			// bufferImage->base64
			ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
			ImageIO.write(vbmDraw, "jpg", outputStream);
			String base64Img = Base64.encodeBase64String(outputStream.toByteArray());
			return base64Img;
		} catch (Exception e) {
			return "";
		}
	}

	private static String getHttpUrl(BufferedImage bmDraw) {
		FileOutputStream fos = null;
		BufferedReader bufferedReader = null;
		try {
			Properties properties = new Properties();
			// 使用InPutStream流读取properties文件
			bufferedReader = new BufferedReader(new FileReader("/hgkj/config/config.product.properties"));
//	        BufferedReader bufferedReader = new BufferedReader(new FileReader("f://config.dev.properties"));
			properties.load(bufferedReader);
			File tempFile = File.createTempFile("cloud", ".jpg");
			fos = new FileOutputStream(tempFile);
			ImageIO.write(bmDraw, "JPEG", fos);
			FileSaver fs = new FileSaver(tempFile);
			FileSourceGenerator fsg = new FileSourceGenerator();
			fsg.setClientDir(properties.getProperty("fileSourceGenerator.clientDir"));
			fsg.setServerPath(properties.getProperty("fileSourceGenerator.serverPath"));
			String localPath = fsg.generatorOpen(fs);
			RemoteServiceImpl remoteService = new RemoteServiceImpl();
			FileProcess fp = new FileProcess();
			fp.setFileBaseDir(properties.getProperty("fileProcess.fileBaseDir"));
			fp.setFileBaseUrl(properties.getProperty("fileProcess.fileBaseUrl"));
			remoteService.setFp(fp);
			remoteService.setServerHost(properties.getProperty("server.host"));
			remoteService.setServerAbsolutePath(properties.getProperty("server.absolute.path"));
			String url = remoteService.processCommonFile(localPath, "test/image");
			return url;
		} catch (Exception e) {
			return "";
		} finally {
			try {
				fos.close();
				bufferedReader.close();
			} catch (Exception e) {
			}
		}
	}
}
